import {
  listAllData,
  getAllProvince,
  getAllProvinceCity,
  getDistrictAndStreet,
  exportOrgData
} from '@/services/orgsettingApi';


export default {
  namespace: 'orgsetting',

  state: {
    // 机构列表
    data: {
      list: [],
      pagination: {},
    },
  },

  effects: {
    *listAllData({ payload }, { call, put }) {
      const response = yield call(listAllData, payload);
      yield put({
        type: 'cb4listAllData',
        payload: response,
      });
    },

    /**
     * 获取所有省份
     * */
    *getAllProvince({ payload }, { call, put }) {
      const response = yield call(getAllProvince, payload);
      return response;
    },

    /**
     * 获取所有省份
     * */
    *getAllProvinceCity({ payload }, { call, put }) {
      const response = yield call(getAllProvinceCity, payload);
      return response;
    },

    /**
     * 获取城市下的区街道信息
     * */
    *getDistrictAndStreet({ payload }, { call, put }) {
      const response = yield call(getDistrictAndStreet, payload);
      return response;
    },

    /**
     * 导出所有机构数据
     * */
    *exportOrgData({ payload }, { call, put }) {
      const response = yield call(exportOrgData, payload);
      return response;
    },
  },

  reducers: {
    cb4listAllData(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
